package com.wzy.Controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzy.entity.Battle;
import com.wzy.entity.Blog;
import com.wzy.service.BattleService;
import com.wzy.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wzy
 * @since 2021-02-09
 */
@Controller

public class BattleController {

    @Autowired
    private BattleService battleService;

    @Autowired
    private BlogService blogService;


    /**
     * 跳转到重大战役页面,未进行数据渲染
     *
     * @return
     */
    @GetMapping("/battle")
    public String routerBattlePage(
            Model model) {
       // @RequestParam(value = "battleId", required = false) Long battleId,
        //查询所有的战役信息

        List<Battle> battles = battleService.listBattle();

        //若传递过来的battleId为空，则默认显示第一个战役的内容
        //if (battleId == null) {
        // battleId = battles.get(0).getBattleId();
        //}

        //分页查询战役所对应的事件
        // Page<Blog> battlePage = new Page<>(current, limit);
        // blogService.getbattleDataByBattleId(battlePage, battleId);


        // System.out.println(battlePage.getRecords().toString());
        model.addAttribute("battles", battles);
        //model.addAttribute("total", battlePage.getTotal());
        //model.addAttribute("hasNext", battlePage.hasNext());
        // model.addAttribute("hasPrevious", battlePage.hasPrevious());
        // model.addAttribute("battleData", battlePage.getRecords());
        //model.addAttribute("curBattleId", battleId);


        return "battle";
    }


}

